#include <cstdio>
#include <queue>
#include <stack>

using namespace std;

const int Size = 1500 + 10;

int father[ Size ], rd[ Size ], n, c[ Size ], lj[ Size ][ Size ];
stack<int> s;

void init( )
{
    int a, b, i, j;
    char tmp;
    for ( i = 0; i < n; i++ )
    {
        father[ i ] = -1;
        rd[ i ] = c[ i ] = 0;
    }
    for ( i = 0; i < n; i++ )
    {
        scanf("%d%c%c", &a, &tmp, &tmp);
        scanf("%d%c", &c[ a ], &tmp);
        for ( j = 0; j < c[ a ]; j++ )
        {
            scanf("%d", &b);
            rd[ b ]++;
            father[ b ] = a;
            lj[ a ][ j ] = b;
        }
    }
}

void topsort( )
{
    int i, p;
    queue<int> q;
    for ( i = 0; i < n; i++ )
        if ( rd[ i ] == 0 )
        {
            q.push( i );
            s.push( i );
            break;
        }
    while ( !q.empty( ) )
    {
        p = q.front( );
        q.pop( );
        for ( i = 0; i < c[ p ]; i++ )
        {
            rd[ lj[ p ][ i ] ]--;
            if ( !rd[ lj[ p ][ i ] ] )
            {
                q.push( lj[ p ][ i ] );
                s.push( lj[ p ][ i ] );
            }
        }
    }
}

void work( )
{
    int i, count = 0, p;
    bool hide[ Size ];
    for ( i = 0; i < n; i++ )
        hide[ i ] = false;
    while ( !s.empty( ) )
    {
        p = s.top( );
        s.pop( );
        if ( hide[ p ] )
            continue;
        if ( father[ p ] == -1 )
            break;
        count++;
        hide[ p ] = true;
        hide[ father[ p ] ] = true;
            for ( i = 0; i < c[ father[ p ] ]; i++ )
                hide[ lj[ father[ p ] ][ i ] ] = true;
    }
    if ( !count )
        puts("1");
    else
        printf("%d\n", count);
}

int main( )
{
    while ( scanf("%d", &n) != EOF )
    {
        init( );
        topsort( );
        work( );
    }
    return 0;
}
